package cn.mesmile.activity.multi;

import org.activiti.bpmn.model.FlowElement;
import org.activiti.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author zb
 * @date 2022/1/14 14:13
 * @Description  统一处理多实例，找审批人
 *       activiti:collection="${actMultiInstanceHandler.getList(execution)}"
 *       //  nrOfCompletedInstances 已经完成的个数
 *       //  nrOfInstances          总的个数
 *       <completionCondition xsi:type="tFormalExpression">${nrOfCompletedInstances/nrOfInstances >= 100}</completionCondition>
 */
@Component
public class ActMultiInstanceHandler {

    public List<String> getList(DelegateExecution execution) {
        // 多实例审批人集合
        Set<String> candidateUserIds = new HashSet<>();
        FlowElement currentFlowElement = execution.getCurrentFlowElement();
        // 节点id
        String id = currentFlowElement.getId();

        // TODO 从配置表里去查询当前节点配置的审批人，添加到 candidateUserIds 集合中
        candidateUserIds.add("zhangsan");
        candidateUserIds.add("lisi");

        return new ArrayList<>(candidateUserIds);
    }

}
